/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package travelmatching;

import java.io.IOException;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Dominik Kopec
 * @todo implement matching
 *
 */
public class Main {

    private static final Logger LOGGER = Logger.getLogger("travelmatching.main");
    private static FileHandler handler;
    private static Date date = new Date();
    private static final Interface OUT = new Interface();

    public static void main(String[] args) {

        Format formater = new SimpleDateFormat("dd - MM - yyyy");
        String currentdate = formater.format(date);
        try {
            handler = new FileHandler(currentdate + ".tm.log.xml");
            LOGGER.addHandler(handler);
            LOGGER.log(Level.FINE, "Initialized Travel Matching Application");
        } catch (IOException ex) {
            LOGGER.log(Level.SEVERE, null, ex);
        } catch (SecurityException ex) {
            LOGGER.log(Level.SEVERE, null, ex);
        }

        OUT.display(OUT.MAINMENU);

        String mainOption = OUT.getIn();
        
        if (mainOption.trim().equals("1")) {

            Access init = new Access();

            String usrId = OUT.inAccId();
            String pass = OUT.inPass();

            if (init.checkPassword(usrId, pass)){

                String[] info = OUT.read(usrId);

                OUT.display(OUT.OPTQUE);

                if (info[2].equals("client")){
                    ClientAccount account = new ClientAccount(usrId);
                    OUT.display(OUT.CLIENTOPT);
                    if(OUT.getIn().equals("1")){
                        account.createMatch();
                    }
                    if(OUT.getIn().equals("2")){
                        account.editAccount();
                    }
                }
                if (info[2].equals("corp")){
                    OUT.display(OUT.CORPOPT);
                    if(OUT.getIn().equals("1")){
                         Registration register = new Registration();
                         register.createUser();
                    }
                }
                if (info[2].equals("admin")){
                    AdminAccount admin = new AdminAccount();
                    OUT.display(OUT.ADMINOPT);
                    if(OUT.getIn().equals("1")){
                        admin.createUserAccount();
                    }
                    if(OUT.getIn().equals("2")){
                        admin.editUserAccount();
                    }
                    if(OUT.getIn().equals("3")){
                        admin.deleteAccount();
                    }
                }
            }
        }
        if (mainOption.trim().equals("2")){
            Registration register = new Registration();
            register.createUser();
            
        }
    }
}
